home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 15709 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.2 KB

  1. Path: gulfa.kuwait.net!shadows
  2. From: shadows@whateva.kuwait.net (The ShadowS Know)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: How to access memory allocated  in function
  5. Date: 21 Apr 1996 11:32:30 GMT
  6. Organization: Gulfnet Kuwait
  7. Message-ID: <slrn4nkrsq.bv6.shadows@whateva.kuwait.net>
  8. References: <4ddbe3$so3@josie.abo.fi>
  9. NNTP-Posting-Host: whateva.kuwait.net
  10. NNTP-Posting-User: shadows
  11. X-Newsreader: slrn (0.8.7.1 UNIX)
  12.  
  13. In article <4ddbe3$so3@josie.abo.fi>, Christoffer Sundqvist wrote:
  14. >Hello
  15. >
  16. >
  17. >How can i access memory allocated dynamically in a function after i leave the 
  18. >function, something like this:
  19. >
  20. >main()
  21. >{
  22. >int *p;
  23. >sub(p);
  24. >}
  25. >
  26. >void sub(int *p)
  27. >{
  28. > p = malloc(.....);
  29. >}
  30. >
  31. >Thanks !
  32. Im sorry ive mailed the person and followed it up here.. *sigh* ok here it goes
  33. again..
  34.  
  35. p = (int *)malloc(sizeof(int));
  36. What we've done is cast it as an pointer to an integer then allocated it
  37. the size of one int (thus it points to a space in memory that has the size
  38. of holding 1 integer). Ofcourse anything might be in that memory address
  39. you'd need to place something there to clear it up. 
  40. -- 
  41. Thamer Al-Herbish
  42. (ShadowS)
  43. "Teenage angst paid off well.. now I'm bored and old."- Kurt Cobain.
  44. -------------------------------------------------------------------------------
  45.  
  46.